Java method invoked sequence

Categories: Java; Tagged with: ; @ May 15th, 2012 20:51

Static block / variable;

Instance block / variable;

Constructor;

public class StaticTest {
	public static void main(String[] args) {
		// System.out.println(B.a);
		// System.out.println(C.c);
		StaticTest staticTest = new StaticTest();
		staticTest.printName();
	}
	
	static {
		System.out.println("Static_block_Main");
	}
	
	
	public StaticTest() {
		System.out.println("Consturctor_Main");
	}
	
	private void printName() {
		System.out.println("InstanceMethod");
	}
	{
		System.out.println("Instance_block_Main");
	}
	
}

Output is:

Static_block_Main
Instance_block_Main
Consturctor_Main
InstanceMethod

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.